//slider
$(function() {
	$( "#slider1" ).slider({
		value:0,
		min: 1,
		max: 100,
		step: 1,
		slide: function( event, ui ) {
			$( "#speed" ).val( ui.value + "x" );
		},
    stop: function( event, ui ) {
      setSimSpeed(ui.value);
    }
	});
	$( "#speed" ).val($( "#slider1" ).slider( "value" ) + "x" );
});

var time=new Date();
var newTime=(time.getHours()*3600)+(time.getMinutes()*60)+time.getSeconds();
var newHours;
var newMinutes;
var newSeconds;
//slider 2
$(function() {
	$( "#slider2" ).slider({
		value: newTime,
		min: 0,
		max: 86399,
		step: 1,
		slide: function( event, ui ) {
			newTime=ui.value;
			newHours= Math.floor(newTime/3600);
			newMinutes=Math.floor((newTime-newHours*3600)/60);
			newSeconds=newTime-newHours*3600-newMinutes*60;
			$( "#time" ).val(newHours+":"+newMinutes+":"+newSeconds);
		},
    stop: function( event, ui ) {
      setSimTime(newHours+":"+newMinutes+":"+newSeconds);
      today = new Date();
      date = new Date(today.getFullYear(), today.getMonth(), today.getDate(),
                        newHours, newMinutes, newSeconds);
    }
	});
	$( "#time" ).val(newHours+":"+newMinutes+":"+newSeconds);
});

$(setInterval("if(newTime<86399) newTime+=simSpeed;\
	else newTime=0;\
	newHours= Math.floor(newTime/3600);\
	newMinutes=Math.floor((newTime-newHours*3600)/60);\
	newSeconds=Math.floor(newTime-newHours*3600-newMinutes*60);\
	$( '#time' ).val(newHours+':'+newMinutes+':'+newSeconds);\
	$('#slider2').slider('value',[newTime]);\
	", 1000)
);
	

// timeTable
$(function(){
	$("#beingFlights").accordion({
		header: 'h3',
		event: 'click'
	});
});

//setRunway
$(function() {
	$( "#berlinTab" ).buttonset();
	$( "#londonTab" ).buttonset();
	$( "#parisTab" ).buttonset();
});
	
	
$(document).ready(function() {
    $("#runway").tabs();
});

//fullscreen
$(document).ready(function(){
    $('#button').toggle(
        function(){
            var windowWidth = innerWidth;
            var windowHeight = innerHeight;
            $('#map').animate({
                width: windowWidth-5,
                height: windowHeight-40,
            }, 1000)
            $('#sliders').hide(1000);
            $('#setRunway').hide(1000);
            $('#beingFlights').hide(1000);
        },
        function(){
            $('#map').animate({
                width: 700,
                height: 500,
            }, 1000)
            $('#sliders').show(1000);
            $('#setRunway').show(1000);
            $('#beingFlights').show(1000);
        }
    ),
    $('input:button').button();
});;

// time changing button
$(function() {
	$( "button, input:submit, a", ".clock" ).button();
	$( "a", ".clock" ).click(function() { return false; });
});
$.fx.speeds._default = 1000;
	$(function() {
		$( "#timeForm" ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode",
			height: "150",
			widht: "300",
			resizable: false
		});

		$( "#clkButt" ).click(function() {
			$( "#timeForm" ).dialog( "open" );
			return false;
		});
		$("#set").button();
		$("#set").click(function() {
			$( "#timeForm" ).dialog( "close" );
			var pattern = /^(([0-1][0-9])|([2][0-3])),([0-5][0-9]),([0-5][0-9])$/;
			var time = $("#setTime").val().split(':',3);
			if(pattern.test(time)){
			newTime=parseInt(time[0],10)*3600+parseInt(time[1],10)*60+parseInt(time[2],10);
            setSimTime(time[0]+":"+time[1]);
			today = new Date();
			date = new Date(today.getFullYear(), today.getMonth(), today.getDate(),
			time[0], time[1], time[2]);
            return false;
			}
			else {alert('Błędny format godziny. Spróbuj ponownie');} 
		});		
	});

	$(function() {
		$( "#controls" ).buttonset();
	});
	

